﻿// Study0616.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第六章 数组和指针 对象指针
//使用指针来访问Point 类的成员

#include <iostream>
using namespace std;

class Point
{
public:
	Point(int xx, int yy) :x(xx), y(yy) {
		count++;
	}
	Point() :x(0), y(0) {
		count++;
	}
	Point(const Point& p) :x(p.getX()), y(p.getY())
	{
		count++;
	}
	~Point() {
		count--;
	}
	int getX() const {
		return x;
	}
	int getY() const {
		return y;
	}
	void setXY(int xx,int yy)
	{
		x = xx;
		y = yy;
		cout << "改变Point对象(" << getX()<<","<<getY() << ")" << endl;
	}
	static void showCount()
	{
		cout << "生成Point对象" << count << "个"<<endl;
	}
private:
	int x, y;
	static int count;
};
int Point::count = 0;
int main()
{
	Point p1(4, 5);
	const Point* ptr1 = &p1;
	cout << "点P1的横坐标是" << ptr1->getX() << endl;
	cout << "点P1的纵坐标是" << ptr1->getY() << endl;
	void (*showptr)()= &Point::showCount;
	showptr();
	Point p2(p1);
	p1.setXY(7, 7);
	cout << "点P1的横坐标是" << ptr1->getX() << endl;
	cout << "点P1的纵坐标是" << ptr1->getY() << endl;
	showptr();
	return 0;
	
}


